<template>
    <view class="container">
        <!-- 导航栏 -->
        <view class="navbar">
            <u-navbar title-color="#fff" back-icon-color="#ffffff" :is-back="true" :background="background"
                :back-text-style="{color: '#fff'}" title="个人信息">
            </u-navbar>
        </view>
        <!-- 用户信息区 -->
        <view class="userInfo">
            <view>
                <u-upload ref="uUpload" :action="action" :auto-upload="false" :form-data="uplloadData" @on-success="success"
                    max-count="1"></u-upload>
            </view>
            <u-form :model="userInfo" ref="uForm">
                <u-form-item label="昵称">
                    <u-input v-model="userInfo.user_name" />
                </u-form-item>
                <u-form-item label="简介">
                    <u-input v-model="userInfo.user_remark" />
                </u-form-item>
                <u-form-item label="性别">
                    <view @click="show = true" style="width: 100%;height: 70rpx;">
                        <u-select v-model="show" :list="list" @confirm="confirm"></u-select>
                    </view>
                </u-form-item>
                <u-form-item label="密码">
                    <u-input v-model="userInfo.user_password" />
                </u-form-item>
            </u-form>
            <u-button @click="submit">提交</u-button>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                show: false,
                background: {
                    'background-image': 'linear-gradient(45deg, rgb(28, 187, 180), rgb(28, 205 ,158))'
                },
                action: 'https://api.bbbug.com/api/attach/uploadimage',
                uplloadData: {
                    access_token: '',
                    plat: "app",
                    version: 10000
                },
                list: [{
                        value: '1',
                        label: '男'
                    },
                    {
                        value: '0',
                        label: '女'
                    }
                ],
                userInfo:''
            }
        },
        onLoad() {
            this.uplloadData.access_token = uni.getStorageSync('token');
            this.myInfo();
        },
        methods: {
            urldecode(str) {
                return decodeURIComponent(str);
            },
            submit() {
                this.$refs.uUpload.upload();
            },
            success(data) {
                console.log(data)
            },
            confirm(e) {
                this.form.user_sex = e[0].value
                this.form.sex = e[0].label
                console.log(e[0]);
            },
            //获取用户信息
            async myInfo() {
                const res = await this.$u.api.getMyInfo({
                    "access_token": this.accessToken
                })
                if (res.code !== 200) {
                    this.$refs.uToast.show({
                        title: res.msg,
                        type: 'error',
                        duration: '2300'
                    })
                    uni.setStorageSync('token', '');
                    console.log(res.msg);
                    this.myInfo();
                }
                this.popupShow = false
                this.userInfo = res.data
                console.log(this.userInfo)
            },
        }
    }
</script>

<style>

</style>
